package cn.wolfcode.edu.web.controller;

import cn.wolfcode.edu.domain.TuitionIncome;
import cn.wolfcode.edu.query.TuitionIncomeQuery;
import cn.wolfcode.edu.service.ITuitionIncomeService;
import cn.wolfcode.edu.util.JsonResult;
import cn.wolfcode.edu.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 徐沅澧 on 2018/7/11.
 */

/**
 * 正式学员收费管理的Controller
 */
@Controller
@RequestMapping("tuitionIncome")
public class TuitionIncomeController {

    @Autowired
    private ITuitionIncomeService incomeService;

    //定位页面
    @RequestMapping("")
    public String index() {
        return "tuitionIncome";
    }
    //列表界面
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(TuitionIncomeQuery qo) {
        return incomeService.query(qo);
    }

    //保存
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(TuitionIncome income) {
        JsonResult result = new JsonResult();
        try {
            incomeService.save(income);
        } catch (Exception e) {
            result = result.remark("保存失败!请检查您输入的数据!");
        }
        return result;
    }
    //更新
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(TuitionIncome income) {
        JsonResult result = new JsonResult();
        try {
            incomeService.update(income);
        } catch (Exception e) {
            result = result.remark("更新失败!请检查您输入的数据!");
        }
        return result;
    }
    //删除
    @RequestMapping("deleteById")
    @ResponseBody
    public JsonResult deleteById(Long id) {
        JsonResult result = new JsonResult();
        try {
            incomeService.deleteById(id);
        } catch (Exception e) {
            result = result.remark("删除失败!请稍后再试!");
        }
        return result;
    }
    //审核
    @RequestMapping("auditById")
    @ResponseBody
    public JsonResult auditById(Long id) {
        JsonResult result = new JsonResult();
        try {
            incomeService.auditById(id);
        } catch (Exception e) {
            result = result.remark("审核失败!请联系管理员!");
        }
        return result;
    }
}